package com.clh.seckill.config;

import com.clh.seckill.filter.InformationFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.*;

import java.util.List;

@Configuration
public class McvConfig implements WebMvcConfigurer {
    @Autowired
    private InformationFilter informationFilter;
    @Autowired
    private UserHandlerArgumentResolver userHandlerArgumentResolver;
    /**
     * mvc拦截器
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // "/**/*.css", "/**/*.js", "/**/*.png", "/**/*.jpg","/**/*.jpeg", "/**/*.gif", "/**/fonts/*", "/**/*.svg"
        registry.addInterceptor(informationFilter).addPathPatterns("/**").excludePathPatterns("/","/login/**")
                .excludePathPatterns("/bootstrap/**","/images/**","/js/**","/jquery-validation/**","/layer/**","/**/*.png")
                ;
    }

    /**
     * 添加静态资源文件，外部可以直接访问地址
     * @param registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //需要配置1：----------- 需要告知系统，这是要被当成静态文件的！
        //第一个方法设置访问路径前缀，第二个方法设置资源路径
        registry.addResourceHandler("/**").addResourceLocations("classpath:/static/");
    }
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addRedirectViewController("/","/login/index");
    }

    /**
     * 添加参数列表拦截器
     * @param resolvers
     */
    @Override
    public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) {
        resolvers.add(userHandlerArgumentResolver);
    }
}
